<template>
    <div>
        <div class="section">
            <div class="location">
                <span>当前位置：</span>
                <a href="/index.html">首页</a> &gt;
                <a href="/login.html">会员登录</a>
            </div>
        </div>
        <div class="section">
            <div class="wrapper">
                <div class="bg-wrap">
                    <div class="nav-tit">
                        <a class="selected" href="javascript:;">账户登录</a>
                        <i>|</i>
                        <a href="/register.html">免费注册</a>
                    </div>

                    <div id="loginform" name="loginform" class="login-box">
                        <div class="input-box">
                            <input id="txtUserName" v-model="user.user_name" name="txtUserName" type="text" placeholder="用户名/手机/邮箱" maxlength="50">
                        </div>
                        <div class="input-box">
                            <input id="txtPassword" v-model="user.password"  name="txtPassword" type="password" placeholder="输入登录密码" maxlength="16">
                        </div>
                        <div class="btn-box">
                            <input id="btnSubmit" @click="login" name="btnSubmit" type="submit" value="立即登录">
                        </div>
                        <div id="msgtips" class="tip-box"></div>
                        <input id="turl" name="turl" type="hidden" value="http://localhost:8020/cart.html">
                        <!--记住上一页网址-->
                    </div>
                </div>
            </div>
        </div>
    </div>
    </div>
</template>

<style scoped>
</style>

<script>
    import {bus,LOGINSTATUSCHANGE,ISLOGIN} from '../../common/commonvue'

    export default {
        data() {
            return {
                user:{
                    user_name:"",
                    password:""
                }
            }
        },
        created() {

        },
        methods: {
            login(){
                const url = "site/account/login"

                this.$axios.post(url,this.user).then(response=>{
                    if(response.data.status==1){
                        this.$message.error(response.data.message)
                        return
                    }

                    //保存登录状态
                    localStorage.setItem(ISLOGIN,"true")

                    //事件总线传递给layout.vue
                    bus.$emit(LOGINSTATUSCHANGE)

                    console.log(localStorage.getItem("lastVisitPath"))
                    this.$router.push({path:localStorage.getItem("lastVisitPath")})
                })
            }
        }
    }
</script>